home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / rng / rng-dump.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-05  |  1.8 KB  |  74 lines

  1. /* rng/rng-dump.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <config.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <gsl/gsl_rng.h>
  24.  
  25. int
  26. main (int argc, char **argv)
  27. {
  28.   int i, j ;
  29.   char buffer[1024 * 4] ;
  30.   gsl_rng * r ;
  31.  
  32.   gsl_rng_env_setup () ;
  33.  
  34.   r = gsl_rng_alloc (gsl_rng_default) ;
  35.  
  36.   if (argc != 1)
  37.     {
  38.       printf ("Usage: diehard\n");
  39.       printf ("Output 3 million numbers in binary format," 
  40.           "suitable for testing with DIEHARD\n");
  41.       exit (0);
  42.     }
  43.  
  44.   argv = 0 ; /* prevent warning about unused argument */
  45.  
  46.   for (i = 0; i < 3000 ; i++)
  47.     {
  48.       int status ;
  49.  
  50.       for (j = 0; j < 1024; j++)
  51.     {
  52.       unsigned long int u = gsl_rng_get (r) ;
  53.       buffer[4 * j + 0] = u & 0xFF ;
  54.       u >>= 8;
  55.       buffer[4 * j + 1] = u & 0xFF ;
  56.       u >>= 8;
  57.       buffer[4 * j + 2] = u & 0xFF ;
  58.       u >>= 8;
  59.       buffer[4 * j + 3] = u & 0xFF ;
  60.  
  61.     }
  62.       
  63.       status = fwrite(buffer, 4 * sizeof(char), 1024, stdout) ;
  64.  
  65.       if (status != 1024) 
  66.     {
  67.       perror("fwrite") ;
  68.       exit(EXIT_FAILURE) ;
  69.     }
  70.     }
  71.  
  72.   return 0;
  73. }
  74.